package com.org.sort;

import java.util.Arrays;
import java.util.concurrent.ForkJoinTask;

@SuppressWarnings("serial")
public class ArrayConcurrentSortComparable<T extends Comparable<? super T>> extends AbConcurrentArrySort<T> {

    public ArrayConcurrentSortComparable(T[] array) {
        super(array);
    }

    public ArrayConcurrentSortComparable(T[] array, int threadloads) {
        super(array, threadloads);
    }

    private ArrayConcurrentSortComparable(T[] array, int began, int end, int threadloads) {
        super(array, began, end, threadloads);
    }

    @Override
    protected int compare(T t1, T t2) {
        return t1.compareTo(t2);
    }

    @Override
    protected ForkJoinTask<Void> invokeTaskLeft(int pos) {
        return new ArrayConcurrentSortComparable<>(array, began, pos - 1, threadloads);
    }

    @Override
    protected ForkJoinTask<Void> invokeTaskRight(int pos) {
        return new ArrayConcurrentSortComparable<>(array, pos + 1, end, threadloads);
    }

    @Override
    public void sortRange(int start, int end) {
        Arrays.sort(array, began, end);
    }

}
